package cn.stylefeng.guns.modular.gridsystem.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.core.exception.ServiceException;
import cn.stylefeng.guns.core.factory.PageFactory;
import cn.stylefeng.guns.core.pojo.page.PageResult;
import cn.stylefeng.guns.modular.gridsystem.entity.BizIndustryInvolved;
import cn.stylefeng.guns.modular.gridsystem.mapper.BizIndustryInvolvedMapper;
import cn.stylefeng.guns.modular.gridsystem.model.param.BizIndustryInvolvedParam;
import cn.stylefeng.guns.modular.gridsystem.service.BizIndustryInvolvedService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * biz_industry_involved 服务实现类
 *
 * @author ssy
 * @date 2021/11/01 15:31
 */
@Service
public class BizIndustryInvolvedServiceImpl extends ServiceImpl<BizIndustryInvolvedMapper, BizIndustryInvolved> implements BizIndustryInvolvedService {

    @Override
    public PageResult<BizIndustryInvolved> page(BizIndustryInvolvedParam bizIndustryInvolvedParam) {

        // 构造条件
        LambdaQueryWrapper<BizIndustryInvolved> queryWrapper = new LambdaQueryWrapper<>();

        // 查询分页结果
        return new PageResult<>(this.page(PageFactory.defaultPage(), queryWrapper));
    }

    @Override
    public List<BizIndustryInvolved> list(BizIndustryInvolvedParam bizIndustryInvolvedParam) {

        // 构造条件
        LambdaQueryWrapper<BizIndustryInvolved> queryWrapper = new LambdaQueryWrapper<>();

        return this.list(queryWrapper);
    }

    @Override
    public void add(BizIndustryInvolvedParam bizIndustryInvolvedParam) {

        // 将dto转为实体
        BizIndustryInvolved bizIndustryInvolved = new BizIndustryInvolved();
        BeanUtil.copyProperties(bizIndustryInvolvedParam, bizIndustryInvolved);

        this.save(bizIndustryInvolved);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(BizIndustryInvolvedParam bizIndustryInvolvedParam) {
        this.removeById(bizIndustryInvolvedParam.getId());
    }

    @Override
    public void edit(BizIndustryInvolvedParam bizIndustryInvolvedParam) {

        // 根据id查询实体
        BizIndustryInvolved bizIndustryInvolved = this.queryBizIndustryInvolved(bizIndustryInvolvedParam);

        // 请求参数转化为实体
        BeanUtil.copyProperties(bizIndustryInvolvedParam, bizIndustryInvolved);

        this.updateById(bizIndustryInvolved);
    }

    @Override
    public BizIndustryInvolved detail(BizIndustryInvolvedParam bizIndustryInvolvedParam) {
        return this.queryBizIndustryInvolved(bizIndustryInvolvedParam);
    }



    /**
     * 获取biz_industry_involved
     *
     * @author ssy
     * @since 2021/11/01 15:31
     */
    private BizIndustryInvolved queryBizIndustryInvolved(BizIndustryInvolvedParam bizIndustryInvolvedParam) {
        BizIndustryInvolved bizIndustryInvolved = this.getById(bizIndustryInvolvedParam.getId());
        return bizIndustryInvolved;
    }
}
